package com.ruoyi.quartz.task;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.service.ISysUserPositionLevelHistoryService;
import com.ruoyi.system.domain.SysUserPosition;
import com.ruoyi.system.mapper.SysUserPositionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 每月月底扫描保存当月所有用户岗位等级信息
 *
 * @author zy
 */
@Component("userPositionHistoryTask")
public class UserPositionHistoryTask {
    @Autowired
    private SysUserPositionMapper sysUserPositionMapper;
    @Autowired
    private ISysUserPositionLevelHistoryService sysUserPositionLevelHistoryService;

    public void insertUserPositionHistory() {
        //获取当前日期
        //String nowDateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, nowDate);
        List<SysUserPosition> sysUserPositionList = sysUserPositionMapper.selectAllUserPosition();
        for (SysUserPosition sysUserPosition : sysUserPositionList) {
            sysUserPositionLevelHistoryService.insertOrUpdateUserPositionHistoryByUserId(sysUserPosition.getPositionId(), sysUserPosition.getUserId(), new Date());
        }
    }
}
